<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>

		<div class="th"></div>
		<script src="../lib/jquery-1.12.1.min.js"></script>
		<script>
			var arr = [
				{
					"type":"radio",
					"title":"题目1",
					"detaile":{
						"a":"这是A选项1",
						"b":"这是B选项1",
						"c":"这是C选项1"
					},
					"answer":[
						"a"
					]
				},
				{
					"type":"radio",
					"title":"题目11",
					"detaile":{
						"a":"这是A选项11",
						"b":"这是B选项11",
						"c":"这是C选项11"
					},
					"answer":[
						"b"
					]
				},
				{
					"type":"checkbox",
					"title":"题目2",
					"detaile":{
						"a":"这是A选项2",
						"b":"这是B选项2",
						"c":"这是C选项2",
						"d":"这是D选项2"
					},
					"answer":[
						"c"
					]
				},
				{
					"type":"checkbox",
					"title":"题目3",
					"detaile":{
						"a":"这是A选项3",
						"b":"这是B选项3",
						"c":"这是C选项3",
						"d":"这是D选项3"
					},
					"answer":[
						"d"
					]
				}
			];

			var newArr = [];
			$.each(arr,function(i,obj) {
				var bArr = [];
				$.each(obj.detaile,function(j,b) {
					bArr.push(
						'<label>',
							'<input name="hobbies',i,'" type="checkbox" value = "',j,'" number="',i,'"/>',
							'<div>',b,'</div>',
						'</label>'
					)
				}); 
				
				newArr.push(
					'<div>',
						'<div>',obj.title,'</div>',
						'<div>',bArr.join(''),'</div>',
					'</div>',
					'<hr>'
				);
				
			});
			newArr.push(
				'<button>提交</button>'
			);
			$('.th').html(newArr.join(''));
			
			var newObj = [];
			
			$('.th').on('click','input',function() {
				var all = $(this).parent().parent().find('input:checked');
				var $number = $(this).attr('number');
				var length = arr[$number].answer.length;
				var tmp = [];
				for(var n=0;n<all.length;n++) {
					tmp.push(all[n].value);
				};
				newObj[$number] = {
					"answer":tmp 
				}
				console.log(newObj)
			});
			
			function check() {
				
				var r = [];
				
				if (arr.length != newObj.length) {
					alert('没做完!');
					return;
				}
				
				$.each(newObj, function(i, obj) {
					if (arr[i].answer.join('') != obj.answer.join('')) {
						r.push(arr[i].title);
//						console.log(arr[i].title)
					}
					
//					console.log(arr)
//					console.log(newObj)
				});
				
				console.log(r)

//				$.each(newObj,function(j,obj) {
//					if(obj.answer.toString() != arr[j].answer.toString()) {
//						return;
//					} 
//					console.log(obj.answer.toString());
//					console.log(arr[j].answer.toString());
//				})
    			
			

				
				
			}
			$('button').on('click',function() {
				check();
		
			});
				
			


//			$('.th').on('click','input',function() {
//		var all = $(this).parent().parent().find('input:checked');
//		var $number = $(this).attr('number');
//		var length = arr[$number].answer.length;
//		var tmpArr = [];
//		for(var n=0;n<all.length;n++) {
//			tmpArr.push(all[n].value);
//		};
//		if(arr[$number].answer.toString().indexOf($(this).val()) == -1) {
//			alert('错误');
//			$(this).get(0).checked = false;
//		} else {
//			if($(this).is(':checked')) {
//				if(tmpArr.toString() == arr[$number].answer.toString()) {
//					alert('本题回答正确')
//				} else {
//					alert('正确')
//				}
//			} 
//		}	
//	})

			
			
			
			
			
			
		</script>
	</body>
</html>
